package com.aiju.cash.ui.member;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.aiju.base.activity.BaseTitleActivity;
import com.aiju.cash.R;
import com.aiju.cash.ui.member.entity.MemberCard;
import com.aiju.cash.util.ImageDialogUtil;
import com.aiju.utils.T;
import com.uuzuche.lib_zxing.activity.CodeUtils;

/**
 * @author: 佐为
 * @date: 2017-02-20 15:59
 * @version: V1.0
 * @Description: 会员卡二维码
 */
public class MemberCardQRActivity extends BaseTitleActivity {

    private MemberCard memberCard;

    private ImageView codeImageView;

    private TextView nameTextView, discontTextView, timeTextView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_member_card_qr);
        setCenterTitle("会员卡二维码");
        memberCard = (MemberCard) getIntent().getSerializableExtra("memberCard");

        nameTextView= (TextView) findViewById(R.id.tv_card_name);
        discontTextView= (TextView) findViewById(R.id.tv_card_discoun);
        timeTextView= (TextView) findViewById(R.id.tv_card_time);
        codeImageView = (ImageView) findViewById(R.id.iv_card_qr);

        nameTextView.setText(memberCard.getName());
        discontTextView.setText(memberCard.getDiscount());
        if (memberCard.isForever()){
            timeTextView.setText("无限期");
        }else {
            timeTextView.setText("有效期："+memberCard.getTime());
        }

        String url = "http://jx8996.gicp.net/member/saveUI?storeId=" + mUser.getStoreId() + "&mCardId=" + memberCard.getId();
        Bitmap mBitmap = CodeUtils.createImage(url, 400, 400, BitmapFactory.decodeResource(getResources(), R.mipmap.icon_launcher));
        codeImageView.setImageBitmap(mBitmap);

        findViewById(R.id.btn_good_add_save).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ImageDialogUtil.saveImageToGallery(MemberCardQRActivity.this, ImageDialogUtil.saveCode(findViewById(R.id.ly_store_save_pic)));
                T.ToastShort("图片已保存到本地 Aiiju/QRCode/");
            }
        });
    }

}
